﻿using Day25WebAPI.Data;
using Day25WebAPI.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Day25WebAPI.Adapters.Data
{
    public class MessageDataAdapter : IMessageAdapter
    {
        public List<MessageViewModel> GetMessageViewModels()
        {
            List<MessageViewModel> models = null;

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                models = db.Messages.Select(m => new MessageViewModel
                {
                    MessageId = m.MessageId,
                    Text = m.Text,
                    Timestamp = m.Timestamp,
                    Username = m.User.UserName
                }).ToList();
            }

            return models;
        }
    }
}